package immutable.factors;

import annotation.Immutable;

import java.math.BigInteger;
import java.util.Arrays;

@Immutable
public class OneValueCache {
    private final BigInteger lastNumber;
    //不可变的引用
    private final BigInteger[] lastFactors;
    public OneValueCache(BigInteger i,BigInteger[] factors){
        lastNumber = i;
        this.lastFactors=factors;
    }
    public BigInteger[] getFactors(BigInteger i){
        if(lastNumber == null || !lastNumber.equals(i)){
            return null;
        }else{
            //不变的对象
            return Arrays.copyOf(lastFactors,lastFactors.length);
        }
    }

}
